package com.zyg.apart.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.PageInfo;
import com.zyg.apart.model.Lessee;
import com.zyg.apart.service.LesseeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("/lessee")
public class LesseeController {
	
	@Autowired
	private LesseeService lesseeService;

	@RequestMapping("/list")
	public String list(Integer currentPage, Model model){
		if (currentPage == null){
			currentPage = 1;
		}
		PageInfo<Map<String,Object>> lss = lesseeService.getAllLS(currentPage);
		model.addAttribute("lss",lss);
		return "lessee/list";
	}

	@RequestMapping("/detail")
	public String detail(Model model,Integer id){
		Lessee lessee = lesseeService.getLSById(id);
		model.addAttribute("lessee",lessee);
		return "lessee/detail";
	}

	@RequestMapping("/toEdit")
	public String toEdit(Model model, Integer id){
		Lessee lessee = lesseeService.getLSById(id);
		model.addAttribute("lessee",lessee);
		return "lessee/edit";
	}

	@RequestMapping("/edit")
	public String edit(Lessee lessee){
		int i = lesseeService.editLessee(lessee);
		return "forward:list";
	}

	@RequestMapping("/toAdd")
	public String toAdd(){
		return "lessee/add";
	}

	@RequestMapping("/add")
	public String add(Lessee lessee){
		int i = lesseeService.addLessee(lessee);
		return "forward:list";
	}

	@RequestMapping("/del")
	public String del(Integer id){
		int i = lesseeService.delLesseeById(id);
		return "forward:list";
	}
}
